/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.entities;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.persistence.SequenceGenerator;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.persistence.GeneratedValue;

/**
 *
 * @author Samy.A.Omar
 */
@Entity
@Table(name = "TICKETS")
@NamedQueries({
    @NamedQuery(name = "Ticket.findAll", query = "SELECT t FROM Ticket t"),
    @NamedQuery(name = "Ticket.findByTicketId", query = "SELECT t FROM Ticket t WHERE t.ticketId = :ticketId"),
    @NamedQuery(name = "Ticket.findByIssueDate", query = "SELECT t FROM Ticket t WHERE t.issueDate = :issueDate"),
    @NamedQuery(name = "Ticket.findByNotes", query = "SELECT t FROM Ticket t WHERE t.notes = :notes"),
    @NamedQuery(name = "Ticket.findByClosingDate", query = "SELECT t FROM Ticket t WHERE t.closingDate = :closingDate"),
    @NamedQuery(name = "Ticket.findByComments", query = "SELECT t FROM Ticket t WHERE t.comments = :comments")})

public class Ticket implements Serializable {
	
    private static final long serialVersionUID = 1L;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation

    @Id 
    @Column(name = "TICKET_ID")
    @SequenceGenerator(name="Ticket_Gen", sequenceName="TICKET_SEQ")
    @GeneratedValue(generator="Ticket_Gen")
    private Integer ticketId;
    
    @Column(name = "ISSUE_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date issueDate;
    
    @Size(max = 500)
    @Column(name = "NOTES")
    private String notes;
    
    @Column(name = "CLOSING_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date closingDate;
    
    @Lob
    @Column(name = "ATTACHED_FILE")
    private byte[] attachedFile;
    
    @Size(max = 2000)
    @Column(name = "COMMENTS")
    private String comments;
    
    @JoinColumn(name = "INITIATOR_USER_ID", referencedColumnName = "USER_ID")
    @ManyToOne(fetch = FetchType.EAGER)
    private User initiatorUser;
    
    @JoinColumn(name = "ASSIGNED_USER_ID", referencedColumnName = "USER_ID")
    @ManyToOne(fetch = FetchType.EAGER)
    private User assignedUser;
    
    @JoinColumn(name = "TICKET_TYPE_ID", referencedColumnName = "TICKET_TYPE_ID")
    @ManyToOne(fetch = FetchType.EAGER)
    private TicketType ticketType;
    
    @JoinColumn(name = "STATUS_ID", referencedColumnName = "STATUS_ID")
    @ManyToOne(fetch = FetchType.EAGER)
    private TicketStatus status;
    
    @JoinColumn(name = "PRIORITY_ID", referencedColumnName = "PRIORITY_ID")
    @ManyToOne(fetch = FetchType.EAGER)
    private Priority priority;
    
    
    @JoinColumn(name = "ASSIGNED_GROUP_ID", referencedColumnName = "GROUP_ID")
    @ManyToOne(fetch = FetchType.EAGER)
    private Group assignedGroup;
    

    public Ticket() {
    	
    }

    public Ticket(Integer ticketId) {
        this.ticketId = ticketId;
    }

    public Integer getTicketId() {
        return ticketId;
    }

    public void setTicketId(Integer ticketId) {
        this.ticketId = ticketId;
    }

    public Date getIssueDate() {
        return issueDate;
    }

    public void setIssueDate(Date issueDate) {
        this.issueDate = issueDate;
    }

    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }

    public Date getClosingDate() {
        return closingDate;
    }

    public void setClosingDate(Date closingDate) {
        this.closingDate = closingDate;
    }



    public byte[] getAttachedFile() {
		return attachedFile;
	}

	public void setAttachedFile(byte[] attachedFile) {
		this.attachedFile = attachedFile;
	}

	public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }

   



    public User getInitiatorUser() {
		return initiatorUser;
	}

	public void setInitiatorUser(User initiatorUser) {
		this.initiatorUser = initiatorUser;
	}

	public User getAssignedUser() {
		return assignedUser;
	}

	public void setAssignedUser(User assignedUser) {
		this.assignedUser = assignedUser;
	}

	public TicketType getTicketType() {
		return ticketType;
	}

	public void setTicketType(TicketType ticketType) {
		this.ticketType = ticketType;
	}

	

	public TicketStatus getStatus() {
		return status;
	}

	public void setStatus(TicketStatus status) {
		this.status = status;
	}

	public Priority getPriority() {
		return priority;
	}

	public void setPriority(Priority priority) {
		this.priority = priority;
	}



	public Group getAssignedGroup() {
		return assignedGroup;
	}

	public void setAssignedGroup(Group assignedGroup) {
		this.assignedGroup = assignedGroup;
	}

	@Override
    public int hashCode() {
        int hash = 0;
        hash += (ticketId != null ? ticketId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Ticket)) {
            return false;
        }
        Ticket other = (Ticket) object;
        if ((this.ticketId == null && other.ticketId != null) || (this.ticketId != null && !this.ticketId.equals(other.ticketId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.entities.Ticket[ ticketId=" + ticketId + " ]";
    }
    
}
